package com.topView2;

import com.bean.TreeNode;

/**
 * @Author: huangzhigao
 * @Date: 2023/2/12 17:27
 */
public class leecode98 {
    public boolean isValidBST(TreeNode root) {
        if(root == null){
            return true;
        }

        return isValid(root,Long.MIN_VALUE, Long.MAX_VALUE);
    }

    public boolean isValid(TreeNode node,long lower,long Upper){
        if(node==null){
            return true;
        }
        if(node.val<=lower || node.val >=Upper){
            return false;
        }
        return isValid(node.left,lower,node.val) && isValid(node.right,node.val,Upper);
    }

}
